#include<bits/stdc++.h>
using namespace std;

int maximizeSum(vector<int>& nums, int k) 
{
    return k**max_element(nums.begin(), nums.end())+k*(k-1)/2;
}

int main()
{
	int x, k;
	vector<int> nums;
	while(cin>>x)
		nums.push_back(x);
	k = nums.back();
	nums.pop_back();
	cout<<maximizeSum(nums, k);
	return 0;
}

